﻿using AutoMapper;

namespace netCoreStudy.Entities.Base
{
	/// <summary>
	/// 给个抽象类,不然会报错 
	/// </summary>
	/// <typeparam name="TEntity"></typeparam>
	/// <typeparam name="TDto"></typeparam>
	/// <typeparam name="TAddDto"></typeparam>
	/// <typeparam name="TUpdateDto"></typeparam>
	public abstract class BaseProfile<TEntity, TDto, TAddDto, TUpdateDto> : AutoMapper.Profile
		where TDto : BaseDto
		where TEntity : BaseEntity
	{
		protected IMappingExpression<TEntity, TDto> Entity2Dto;
		protected IMappingExpression<TAddDto, TEntity> Add2Entity;
		protected IMappingExpression<TUpdateDto, TEntity> Update2Entity;

		protected BaseProfile()
		{
			Entity2Dto = CreateMap<TEntity, TDto>()
				.ForMember(d => d.CreateTimeStr, o => o.MapFrom(s => s.CreateTime.Ts2DateTime().ToString("yyyy-MM-dd HH:mm:ss")));
			Add2Entity = CreateMap<TAddDto, TEntity>();
			Update2Entity = CreateMap<TUpdateDto, TEntity>();
		}
	}
}